package com.liu.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    /**
     * 注入错误日志队列
     * @return
     */
    @Bean
    public Queue queueError(){
        return new Queue("error-log");
    }

    /**
     *记录基本信息日志的队列
     * @return
     */
    @Bean
    public Queue queueInfo(){
        return new Queue("info-log",true,false,false,null);
    }


    @Bean
    public  Queue queueOrder(){
        return  new Queue("order-log");
    }

    /**
     * 向容器注入话题交换器
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("log-ex");
    }

    /**
     * 绑定错误日志队列和交换器
     * @param topicExchange
     * @param queueError
     * @return
     */
    @Bean
    public Binding bindingQueueError(TopicExchange topicExchange,Queue queueError){
        return BindingBuilder.bind(queueError).to(topicExchange).with("*.*.error");
    }

    /**
     * 绑定基本信息日志队列和交换器
     * @param topicExchange
     * @param queueInfo
     * @return
     */
    @Bean
    public Binding bindingQueueInfo(TopicExchange topicExchange,Queue queueInfo){
        return BindingBuilder.bind(queueInfo).to(topicExchange).with("*.*.info");
    }
    /**
     * 绑定基本信息日志队列和交换器
     * @param topicExchange
     * @param queueOrder
     * @return
     */
    @Bean
    public Binding bindingQueueOrder(TopicExchange topicExchange,Queue queueOrder){
        return BindingBuilder.bind(queueOrder).to(topicExchange).with("order.#");
    }

}
